package com.wpw.java7demo.collections;

import java.util.Map.Entry;  
import java.util.concurrent.ConcurrentHashMap; 
public class ConHashMapTest {
	 private static ConcurrentHashMap<String,Integer> map = new ConcurrentHashMap<String,Integer>();  
	 private static String[] array = {"yy","yy","welcome","java","234","java","1234","yy","welcome","java","234"};  
	      
	    public static void main(String[] args) {  
	  
	        System.out.println("array size:"+array.length);  
	        for (String str : array) {  
	            new Thread(new MyTask(str)).start();  
	        }  
	  
	        for(Entry<String,Integer> entry : map.entrySet()){  
	            System.out.println(entry.getKey()+":"+entry.getValue());  
	        }  
	    }  
	  
	    static class MyTask implements Runnable{  
	        String key;  
	  
	        public MyTask(String key) {  
	            this.key = key;  
	        }  
	        @Override  
	        public void run() {
	        	//map.putIfAbsent(key, value)
	            Integer value = map.get(key);  
	            if(null == value){  
	                map.put(key, 1);  
	            }else{  
	                map.put(key, value + 1);  
	            }  
	  
	        }  
	  
	    }  
	  
	  
	}  
